package com.guazi.trackingtest.filter;

import com.guazi.trackingtest.Constants;
import com.guazi.trackingtest.PackData;

public class Noise {

    private double noiseDeltaError = Constants.NOISE_DELTA_ERROR;

    public Noise() {

    }

    public void setNoiseDeltaError(double noiseDeltaError) {
        this.noiseDeltaError = Math.abs(noiseDeltaError);
    }

    public PackData filter(PackData sensorSingleData) {
        if (sensorSingleData.x < noiseDeltaError &&
                sensorSingleData.x > -noiseDeltaError) {
            sensorSingleData.setX(0);
        }

        if (sensorSingleData.y < noiseDeltaError &&
                sensorSingleData.y > -noiseDeltaError) {
            sensorSingleData.setY(0);
        }

        if (sensorSingleData.z < noiseDeltaError &&
                sensorSingleData.z > -noiseDeltaError) {
            sensorSingleData.setZ(0);
        }

        return sensorSingleData;
    }
}
